package com.yyjj.yyjj.common.exception;

import com.yyjj.yyjj.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//全局异常处理器
//AOP面向切面编程
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail(null);
    }

    //自定义异常处理
    @ExceptionHandler(YYJJException.class)
    @ResponseBody
    public Result error(YYJJException e){
        return Result.build(null,e.getCode(),e.getMessage());
    }

}
